package com.wly.dbc.parser;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.wly.datapool.heropool.HeroStaticPool;
import com.wly.datapool.heropool.hero.HeroStatic;
import com.wly.datapool.skillpool.skill.SkillStatic;
import com.wly.define.IDZoneDefine;
import com.wly.define.ParserDefine;

public class HeroParser extends BaseParser
{
	private HeroStaticPool _heroPool = HeroStaticPool.getInstance();
	
	public HeroParser()
	{
		// TODO Auto-generated constructor stub
	}

	@Override
	public int getParserId()
	{
		// TODO Auto-generated method stub
		return ParserDefine.HERO_PARSER;
	}

	@Override
	public String getXmlFileName()
	{
		// TODO Auto-generated method stub
		return "greateHero.xml";
	}

	@Override
	public void doParser(Document doc)
	{
		// TODO Auto-generated method stub
		try
		{
			HeroStatic hero;
			NodeList nl = doc.getElementsByTagName("greateHero");
			Node nodeTmp;
			NamedNodeMap attrs;
			for (int i = 0; i < nl.getLength(); i++)
			{
				hero = new HeroStatic();
				attrs = nl.item(i).getAttributes();
				hero.id           = Integer.parseInt(attrs.getNamedItem("templateId").getNodeValue())+IDZoneDefine.HERO_START_ID;
				hero.name         = attrs.getNamedItem("name").getNodeValue();
				hero.desc         = attrs.getNamedItem("desc").getNodeValue();
				hero.leaderTalent = Integer.parseInt(attrs.getNamedItem("captain").getNodeValue());
				hero.attackTalent = Integer.parseInt(attrs.getNamedItem("force").getNodeValue());
				hero.strengthTalent = Integer.parseInt(attrs.getNamedItem("physique").getNodeValue());
				hero.tenacityTalent = Integer.parseInt(attrs.getNamedItem("endurance").getNodeValue());
				hero.speedTalent  = Integer.parseInt(attrs.getNamedItem("speed").getNodeValue());
				hero.skills.add(Integer.parseInt(attrs.getNamedItem("skill1").getNodeValue()));
				hero.skills.add(Integer.parseInt(attrs.getNamedItem("skill2").getNodeValue()));
				hero.skills.add(Integer.parseInt(attrs.getNamedItem("skill3").getNodeValue()));
				_heroPool.getHeroList().add(hero);
			}
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

}
